package besteAukera;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.util.Vector;

public class Kodegailua extends Konbinazionalak {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private Color kolorea;
	private Vector<Hanka> hankaBektorea = new Vector<Hanka>();
	private Vector<Hanka> sarreraBektorea = new Vector<Hanka>();
	private Hanka s1, s2, s4, s5, i1, i2,i3, s3,s6,s7,s8,s9;
	public Kodegailua(int x1, int y1, int hankaKop, int sarreraKopMax,
			String mota, Color kolorea) {
		super(x1, y1, hankaKop, sarreraKopMax, mota, kolorea);
		// TODO Auto-generated constructor stub
		if (this.mota.compareTo("lau")==0){
		s1 = new Hanka(x - 20, y+10, "positiboa", "s", 0, this, "h", "ez",true);
		s2 = new Hanka(x - 20, y + 30, "positiboa", "s", 1, this, "h", "ez",true);
		s3 = new Hanka(x -20, y+50, "positiboa", "s", 2, this, "h", "ez",true);
		s4 = new Hanka(x -20, y + 70, "positiboa", "s", 3, this, "h", "ez",true);
		s5 = new Hanka(x + 20, y - 10, "negatiboa", "s", 4, this, "b", "ez",true);
		i1 = new Hanka(x + 60, y + 30, "positiboa", "i", 5, this, "h", "ez",true);
		i2 = new Hanka(x + 60, y + 50, "positiboa", "i", 6, this, "h", "ez",true);
	
		lotList[0] = s1;
		lotList[1] = s2;
		lotList[2] = s3;
		lotList[3] = s4;
		lotList[4] = s5;
		lotList[5] = i1;
		lotList[6] = i2;
		}
		if (this.mota.compareTo("zortzi")==0){
			s1 = new Hanka(x - 20, y - 15, "positiboa", "s", 0, this, "h", "ez",false);
			s2 = new Hanka(x - 20, y , "positiboa", "s", 1, this, "h", "ez",false);
			s3 = new Hanka(x - 20, y + 15, "positiboa", "s", 2, this, "h", "ez",false);
			s4 = new Hanka(x - 20, y + 30, "positiboa", "s", 3, this, "h", "ez",false);
			s5 = new Hanka(x - 20, y + 45, "positiboa", "s", 4, this, "h","ez",false);
			s6 = new Hanka(x - 20, y + 60, "positiboa", "s", 5, this, "h","ez",false);
			s7 = new Hanka(x - 20, y + 75, "positiboa", "s", 6, this, "h","ez",false);
			s8 = new Hanka(x - 20, y + 90, "positiboa", "s", 7, this, "h","ez",false); 
			s9 = new Hanka(x + 30, y-23 , "negatiboa", "s", 8, this, "b", "ez",true);
			i1 = new Hanka(x + 70, y +15, "positiboa", "i", 9, this, "h", "ez",false);
			i2 = new Hanka(x + 70, y +35, "positiboa", "i", 10, this, "h", "ez",false);
			i3 = new Hanka(x + 70, y + 55, "positiboa", "i", 11, this, "h","ez",false);
			lotList[0] = s1;
			lotList[1] = s2;
			lotList[2] = s3;
			lotList[3] = s4;
			lotList[4] = s5;
			lotList[5] = s6;
			lotList[6] = s7;
			lotList[7] = s8;
			lotList[8] = s9;
			lotList[9] = i1;
			lotList[10] = i2;
			lotList[11] = i3;
			
		}
	}
	public void marraztu(Graphics g) {

		if (getAukeratua() == true) {
			kolorea = Color.GRAY;
		} else {
			kolorea = Color.black;
		}
		g.setColor(kolorea);
		if (this.mota.compareTo("lau")==0){
		// goikoa
		g.drawLine(x, y, x + 40, y + 20);
		// beikoa
		g.drawLine(x, y + 80, x + 40, y + 60);
		// ezkerretakoa
		g.drawLine(x, y , x, y + 80);
		// eskubitakoa
		g.drawLine(x + 40, y + 20, x + 40, y + 60);
		Font lehenetsia=g.getFont();
		Font f=new Font("name",Font.BOLD,9);
		g.setFont(f);
		g.drawString("0", x+33, y+35);
		g.drawString("1", x+33 , y + 55);
		g.drawString("0", x + 2, y + 15);
		g.drawString("1", x + 2, y + 35);
		g.drawString("2", x + 2, y + 55);
		g.drawString("3", x + 2, y + 75);
	g.setFont(lehenetsia);
		g.setColor(kolorea);
		s1.marraztu(g);
		s2.marraztu(g);
		s3.marraztu(g);
		s4.marraztu(g);
		s5.marraztu(g);
		i1.marraztu(g);
		i2.marraztu(g);
		}
		if (this.mota.compareTo("zortzi")==0){
			// goikoa
			g.drawLine(x, y -24, x + 50, y +10);
			// beikoa
			g.drawLine(x,  y + 99, x + 50, y + 65);
			// ezkerretakoa
			g.drawLine(x, y - 24, x,  y + 99);
			// eskubitakoa
			g.drawLine(x + 50, y + 10, x + 50, y + 65);
			Font lehenetsia=g.getFont();
			Font f=new Font("name",Font.BOLD,9);
			g.setFont(f);
			g.drawString("0", x+44, y+20);
			g.drawString("1", x+44 , y + 40);
			g.drawString("2", x+44 , y + 60);
			g.drawString("0", x + 2, y -10);
			g.drawString("1", x + 2, y + 5);
			g.drawString("2", x + 2, y + 20);
			g.drawString("3", x + 2, y + 35);
			g.drawString("4", x + 2, y + 50);
			g.drawString("5", x + 2, y + 65);
			g.drawString("6", x + 2, y + 80);
			g.drawString("7", x + 2, y + 95);
		g.setFont(lehenetsia);
			g.setColor(kolorea);

			s1.marraztu(g);
			s2.marraztu(g);
			s3.marraztu(g);
			s4.marraztu(g);
			s5.marraztu(g);
			s6.marraztu(g);
			s7.marraztu(g);
			s8.marraztu(g);
			s9.marraztu(g);
			i1.marraztu(g);
			i2.marraztu(g);
			i3.marraztu(g);

		}
		}
	public boolean barruanDago(int x, int y) {
		if ((x > this.x) && (x < (this.x + 40)) && (y > this.y)
				&& (y < (this.y + 70))) {
			return true;
		}
		return false;

	}
	@Override
	public void funtzioLogikoa(Integer... values) {

		// TODO Auto-generated method stub
		if (this.mota.compareTo("lau")==0){
			if (s5.getSarrera().getBalioa().equals(0)){
				lotList[5].getIrteera().setBalioa(0);
				lotList[6].getIrteera().setBalioa(0);
			}
			else if(s5.getSarrera().getBalioa().equals(1)){
				if((s2.getSarrera().getBalioa()==0)&&(s3.getSarrera().getBalioa()==0)&&(s4.getSarrera().getBalioa()==0)){
					lotList[5].getIrteera().setBalioa(0);
					lotList[6].getIrteera().setBalioa(0);
				}
				else if(s2.getSarrera().getBalioa().equals(1)){
					lotList[5].getIrteera().setBalioa(1);
					lotList[6].getIrteera().setBalioa(0);
				}
				else if(s3.getSarrera().getBalioa().equals(1)){
					lotList[5].getIrteera().setBalioa(0);
					lotList[6].getIrteera().setBalioa(1);
				}
				else if(s4.getSarrera().getBalioa().equals(1)){
					lotList[5].getIrteera().setBalioa(1);
					lotList[6].getIrteera().setBalioa(1);
				}
			}
		}
		if (this.mota.compareTo("zortzi")==0){
		if(s9.getSarrera().getBalioa().equals(0)){
			lotList[9].getIrteera().setBalioa(0);
			lotList[10].getIrteera().setBalioa(0);
			lotList[11].getIrteera().setBalioa(0);
		}
		else {
			if((s8.getSarrera().getBalioa().equals(0))&&(s7.getSarrera().getBalioa().equals(0))&&(s6.getSarrera().getBalioa().equals(0))&&(s5.getSarrera().getBalioa().equals(0))&&(s4.getSarrera().getBalioa().equals(0))&&(s3.getSarrera().getBalioa().equals(0))&&(s2.getSarrera().getBalioa().equals(0))&&(s1.getSarrera().getBalioa().equals(0))){
				lotList[9].getIrteera().setBalioa(0);
				lotList[10].getIrteera().setBalioa(0);
				lotList[11].getIrteera().setBalioa(0);
			}
			else if (s8.getSarrera().getBalioa().equals(1)){
				lotList[9].getIrteera().setBalioa(1);
				lotList[10].getIrteera().setBalioa(1);
				lotList[11].getIrteera().setBalioa(1);
			}
			else if (s7.getSarrera().getBalioa().equals(1)){
				lotList[9].getIrteera().setBalioa(1);
				lotList[10].getIrteera().setBalioa(1);
				lotList[11].getIrteera().setBalioa(0);
			}
			else if (s6.getSarrera().getBalioa().equals(1)){
				lotList[9].getIrteera().setBalioa(1);
				lotList[10].getIrteera().setBalioa(0);
				lotList[11].getIrteera().setBalioa(1);
			}
			else if (s5.getSarrera().getBalioa().equals(1)){
				lotList[9].getIrteera().setBalioa(0);
				lotList[10].getIrteera().setBalioa(0);
				lotList[11].getIrteera().setBalioa(1);
			}
			else if (s4.getSarrera().getBalioa().equals(1)){
				lotList[9].getIrteera().setBalioa(0);
				lotList[10].getIrteera().setBalioa(1);
				lotList[11].getIrteera().setBalioa(1);
			}
			else if (s3.getSarrera().getBalioa().equals(1)){
				lotList[9].getIrteera().setBalioa(0);
				lotList[10].getIrteera().setBalioa(1);
				lotList[11].getIrteera().setBalioa(0);
			}
			else if (s2.getSarrera().getBalioa().equals(1)){
				lotList[9].getIrteera().setBalioa(1);
				lotList[10].getIrteera().setBalioa(0);
				lotList[11].getIrteera().setBalioa(0);
			}
			
		}
		}
		}

	@Override
	public Vector<Hanka> getHankak() {
		// TODO Auto-generated method stub
		hankaBektorea = new Vector<Hanka>();
		if(this.mota.compareTo("lau")==0){
		hankaBektorea.addElement(s1);
		hankaBektorea.addElement(s2);
		hankaBektorea.addElement(s3);
		hankaBektorea.addElement(s4);
		hankaBektorea.addElement(s5);
		hankaBektorea.addElement(i1);
		hankaBektorea.addElement(i2);
		}
		if(this.mota.compareTo("zortzi")==0){
			hankaBektorea.addElement(s1);
		hankaBektorea.addElement(s2);
		hankaBektorea.addElement(s3);
		hankaBektorea.addElement(s4);
		hankaBektorea.addElement(s5);
		hankaBektorea.addElement(s6);
		hankaBektorea.addElement(s7);
		hankaBektorea.addElement(s8);
		hankaBektorea.addElement(s9);
		hankaBektorea.addElement(i1);
		hankaBektorea.addElement(i2);
		hankaBektorea.addElement(i3);
		}
		return hankaBektorea;
		
	}

	@Override
	public Vector<Hanka> getSarreraHankak() {
		// TODO Auto-generated method stub
		sarreraBektorea = new Vector<Hanka>();
		if (this.mota.compareTo("lau")==0)
		{
		sarreraBektorea.addElement(s1);
		sarreraBektorea.addElement(s2);
		sarreraBektorea.addElement(s3);
		sarreraBektorea.addElement(s4);
		sarreraBektorea.addElement(s5);
		}
		if (this.mota.compareTo("zortzi")==0){
			sarreraBektorea.addElement(s1);
			sarreraBektorea.addElement(s2);
			sarreraBektorea.addElement(s3);
			sarreraBektorea.addElement(s4);
			sarreraBektorea.addElement(s5);
			hankaBektorea.addElement(s6);
			hankaBektorea.addElement(s7);
			hankaBektorea.addElement(s8);
			hankaBektorea.addElement(s9);
		}
		return sarreraBektorea;
	}
}
